package smartfleet.mobile.rest.webservice.location;

import smartfleet.mobile.location.Location;
import smartfleet.mobile.rest.webservice.client.RestClient;
import smartfleet.mobile.util.parser.SmartFleetParser;
import android.util.Log;

public class LocationWebServiceUtil {
	
	static final String SERVICE_URL = "/smartfleetcserver/web/services/locationws";
	static final String FIND_METHOD = "/find";
	static final String REGISTER_METHOD = "/register";
	
	public static Location getLocationInfo(String idLocation) {
		String url = SERVICE_URL + FIND_METHOD + "/" + idLocation;

		Location location = null;
		try {
			String response = RestClient.doGet(url);
			location = SmartFleetParser.toLocation(response);

		} catch (Exception e) {
			Log.d("Error: ", e.getMessage());
		}

		return location;

	} //

	public static void registerLocationInfo(Location location) {
		String url = SERVICE_URL + REGISTER_METHOD + "/";

		url += location.getName() + "/"
				+ location.getLatitude() + "/" + location.getLongitude();
		try {
			String response = RestClient.doGet(url);
			System.out.println("register location info: " + response);
		} catch (Exception e) {
			System.out
					.println("Houver erro ao registar a location no central server");
			e.printStackTrace();
		}

	} //

}
